<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
      :rules="rules"
    >
<!--      <el-form-item label="用户编号" prop="consNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.consNo"-->
<!--          placeholder="请输入用户编号"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--          class="!w-240px"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="客户名称" prop="consName" label-width="120px">
        <el-input
          v-model="queryParams.consName"
          placeholder="用户名称大于4个汉字"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
          label-width="68px"
        />
      </el-form-item>

      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<!--        <el-button @click="handleExport"><Icon class="mr-5px" icon="ep:download" />导出</el-button>-->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table
        row-key="id"
        highlight-current-row="true"
        v-loading="loading"
        :data="list"
        :stripe="true"
        :show-overflow-tooltip="true"
        @selection-change="handleRowCheckboxChange"

    >
    <el-table-column type="selection" width="55" />
      <el-table-column label="客户名称" align="center" prop="consName"  width="200px"/>
      <el-table-column label="用户编号" align="center" prop="consNo"  width="140px"/>
      <el-table-column label="总电量" align="center" prop="totaldl" />
      <el-table-column label="市场化属性" align="center" prop="schsx" />
<!--      <el-table-column label="城市" align="center" prop="city" />-->
<!--      <el-table-column label="ID" align="center" prop="id" />-->
      <el-table-column label="供电单位" align="center" prop="org" />
<!--      <el-table-column label="客户编号" align="center" prop="custNo" />-->


      <el-table-column label="用电地址" align="center" prop="address" />
      <el-table-column label="合同容量" align="center" prop="htrl" />
      <el-table-column label="运行容量" align="center" prop="yxrl" />
<!--      <el-table-column label="城乡标志" align="center" prop="cxbz" />-->
      <el-table-column label="用户行业类别" align="center" prop="hylb" />
<!--      <el-table-column label="客户分类" align="center" prop="hkfl" />-->
<!--      <el-table-column label="临时电标志" align="center" prop="lsdbz" />-->

      <el-table-column label="用电类别" align="center" prop="ydlb" />
      <el-table-column label="用户电压" align="center" prop="dhdy" />
<!--      <el-table-column label="用户状态" align="center" prop="status" />-->
<!--      <el-table-column label="202308电量" align="center" prop="dl202408" />-->
<!--      <el-table-column label="202308电费" align="center" prop="df202308" />-->
      <el-table-column label="202409电量" align="center" prop="dl202309" />
<!--      <el-table-column label="202309电费" align="center" prop="df202309" />-->
      <el-table-column label="202410电量" align="center" prop="dl202310" />
<!--      <el-table-column label="202310电费" align="center" prop="df202310" />-->
      <el-table-column label="202411电量" align="center" prop="dl202311" />
<!--      <el-table-column label="202311电费" align="center" prop="df202311" />-->
      <el-table-column label="202412电量" align="center" prop="dl202312" />
<!--      <el-table-column label="202312电费" align="center" prop="df202312" />-->
      <el-table-column label="202501电量" align="center" prop="dl202401" />
<!--      <el-table-column label="202401电费" align="center" prop="df202401" />-->
      <el-table-column label="202502电量" align="center" prop="dl202402" />
<!--      <el-table-column label="202403电费" align="center" prop="df202402" />-->
      <el-table-column label="202503电量" align="center" prop="dl202403" />
<!--      <el-table-column label="202403电费" align="center" prop="df202403" />-->
      <el-table-column label="202504电量" align="center" prop="dl202404" />
<!--      <el-table-column label="202404电费" align="center" prop="df202404" />-->
      <el-table-column label="202505电量" align="center" prop="dl202405" />
<!--      <el-table-column label="202405电费" align="center" prop="df202405" />-->
      <el-table-column label="202506电量" align="center" prop="dl202406" />
<!--      <el-table-column label="202406电费" align="center" prop="df202406" />-->
      <el-table-column label="202507电量" align="center" prop="dl202407" />
<!--      <el-table-column label="202407电费" align="center" prop="df202407" />-->
      <el-table-column label="202508电量" align="center" prop="dl202408" />
<!--      <el-table-column label="202408电费" align="center" prop="df202408" />-->


<!--      <el-table-column label="总电费" align="center" prop="totaldf" />-->
      <el-table-column label="法人联系人电话" align="center" prop="frlxdh" />
      <el-table-column label="法人联系人" align="center" prop="frlxr" />
      <el-table-column label="经办人电话" align="center" prop="jbrdh" />
      <el-table-column label="经办人" align="center" prop="jbr" />
      <el-table-column label="账务联系人电话" align="center" prop="cwlxdh" />
      <el-table-column label="账务联系人" align="center" prop="cwlxr" />
      <el-table-column label="电气联系人电话" align="center" prop="dqlxdh" />
      <el-table-column label="电气联系人" align="center" prop="dqlxr" />
      <el-table-column label="停送电联系人电话" align="center" prop="tsdlxdh" />
      <el-table-column label="停送电联系人" align="center" prop="tsdlxr" />
<!--      <el-table-column label="操作" align="center" min-width="120px">-->
<!--        <template #default="scope">-->
<!--          <el-button-->
<!--            link-->
<!--            type="primary"-->
<!--            @click="openForm('update', scope.row.id)"-->
<!--            v-hasPermi="['knowledge:elec-data-contact:update']"-->
<!--          >-->
<!--            编辑-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            link-->
<!--            type="danger"-->
<!--            @click="handleDelete(scope.row.id)"-->
<!--            v-hasPermi="['knowledge:elec-data-contact:delete']"-->
<!--          >-->
<!--            删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <ElecDataContactForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { isEmpty } from '@/utils/is'
import download from '@/utils/download'
import { ElecDataContactApi, ElecDataContact } from '@/api/knowledge/elecdatacontact'
import ElecDataContactForm from './ElecDataContactForm.vue'

/** 用电信息 列表 */
defineOptions({ name: 'ElecDataContact' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(false) // 列表的加载中
const list = ref<ElecDataContact[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  consNo: undefined,
  consName: undefined,

})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
// 添加表单验证规则
const rules = reactive({

  consName: [
    { required: true, message: '请输入用户名称', trigger: ['blur', 'change'] },
    { min: 4, max: 50, message: '用户名称长度至少大于4个汉字', trigger: 'blur' }
  ]
})
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ElecDataContactApi.getElecDataContactPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
// 修改搜索按钮操作，添加表单验证
const handleQuery = async () => {
  // 先验证表单
  const valid = await queryFormRef.value.validate()
  if (valid) {
    queryParams.pageNo = 1
    getList()
  }
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  // handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ElecDataContactApi.deleteElecDataContact(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 批量删除用电信息 */
const handleDeleteBatch = async () => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    await ElecDataContactApi.deleteElecDataContactList(checkedIds.value);
    message.success(t('common.delSuccess'))
    await getList();
  } catch {}
}

const checkedIds = ref<number[]>([])
const handleRowCheckboxChange = (records: ElecDataContact[]) => {
  checkedIds.value = records.map((item) => item.id);
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await ElecDataContactApi.exportElecDataContact(queryParams)
    download.excel(data, '用电信息.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  // getList()
})
</script>
<style scoped>
/* 深度穿透（若使用 scoped） */
:deep(.custom-table .el-table__body tr.current-row>td) {
  background-color: #b01660 !important;
}
/* 悬停效果 */
:deep(.custom-table .el-table__body tr.hover-row>td) {
  background-color: #ac07e3 !important;
}
</style>

